public class MultExpression extends AddExpression
{

	DataInfo dataInfo;

	public PrimaryExpression num;
	public int op;
	public MultExpression tr;

	public static final int TO = 1;
	public static final int DO = 2;
	public static final int MD = 3;

	public MultExpression()
	{

	}

	public MultExpression( PrimaryExpression n, int o, MultExpression t, DataInfo dataInfo )
	{
		num = n;
		op = o;
		tr = t;

		this.dataInfo = dataInfo;
	}

	public String toString()
	{
		String ret = "MultExpression\n";

		String s = "";
		s += "| " + num;
		if( tr != null )
		{
			if( op == TO )
				s += "| " + "*\n";

			else if( op == DO )
				s += "| " + "/\n";

			else if( op == MD )
				s += "| " + "%\n";
			s += "| " + tr.toString();

		}

		for( String st : s.split( "\n" ) )
			ret += "| " + st + "\n";

		return ret;
	}

	public String getType() throws SemanticException
	{

		// if(tr != null)
		// return("int");
		return (num.getType());

	}

	public void check() throws SemanticException
	{

		if( tr != null )
		{

			if( !tr.getType().equalsIgnoreCase( num.getType() ) || (!num.getType().equalsIgnoreCase( "int" ) && !num.getType().equalsIgnoreCase( "float" )) )
			{
				String details = "The children of the arithmetic expression do not have the same type or are not numbers.";
				if( dataInfo != null )
					throw new SemanticException( dataInfo.lineNumber, dataInfo.charNumber, dataInfo.line, details );
				else
					throw new SemanticException( details );
			}
			num.check();
			tr.check();

		}
		else
		{

			num.check();

		}

	}

}